package demo5;
/// 多态
///1. 必须在继承体系下
///2. 子类必须要对父类中方法进行重写
///3. 通过父类的引用调用重写的方法

class Anmial{
    int age;
    String name;

    public Anmial(int age, String name){
        this.age = age;
        this.name = name;
    }

    public void eat(){
        System.out.println(name + "吃饭");
    }
}

//必须在继承体系下
class Dog extends Anmial{
    public Dog(int age, String name) {
        super(age, name);
    }

    //子类必须要对父类中方法进行重写
    public void eat(){
        System.out.println(name + "在吃狗粮");
    }
}

public class Test {
    public static void main(String[] args) {
        //通过父类的引用调用重写的方法
        Anmial anmial = new Dog(12,"啵啵虎");
        anmial.eat();
    }
}
